home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_ldap.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  1.3 KB  |  66 lines

  1. /*
  2.   decode_ldap.c
  3.  
  4.   Lightweight Directory Access Protocol.
  5.   
  6.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  7.  
  8.   $Id: decode_ldap.c,v 1.1 2000/05/16 17:31:14 dugsong Exp $
  9. */
  10.  
  11. #include <sys/types.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "asn1.h"
  15. #include "decode.h"
  16.  
  17. int
  18. decode_ldap(u_char *buf, int len)
  19. {
  20.     u_char *p, *q;
  21.     int i, type, alen = len;
  22.     char *dn, *auth;
  23.     
  24.     Buf[0] = '\0';
  25.     
  26.     for (q = buf; q + 10 < buf + len; q += alen) {
  27.         p = q;
  28.         type = asn1_type(&p);
  29.         if ((alen = asn1_len(&p)) <= 0) break;
  30.         alen += (p - q);
  31.         
  32.         if (type != ASN1_SEQUENCE)        /* LDAPMessage */
  33.             continue;
  34.         
  35.         if (asn1_type(&p) != ASN1_INTEGER)    /* messageID */
  36.             continue;
  37.         p += asn1_len(&p);
  38.         
  39.         if (*p != 0x60) continue;        /* op */
  40.         p += 2;
  41.         
  42.         if (asn1_type(&p) != ASN1_INTEGER)    /* version */
  43.             continue;
  44.         p += asn1_len(&p);
  45.         
  46.         if (asn1_type(&p) != ASN1_STRING)    /* name */
  47.             continue;
  48.         if ((i = asn1_len(&p)) <= 0)
  49.             continue;
  50.         
  51.         p--; memmove(p, p + 1, i); p[i] = '\0';    /* XXX - i suk */
  52.         dn = p;
  53.         p += (i + 1);
  54.         
  55.         if (*p++ != 0x80) continue;        /* simple auth [0] */
  56.         if ((i = asn1_len(&p)) <= 0)
  57.             continue;
  58.         p--; memmove(p, p + 1, i); p[i] = '\0';    /* XXX - i suk */
  59.         auth = p;
  60.         
  61.         snprintf(Buf, sizeof(Buf) - strlen(Buf), "%s\n%s\n", dn, auth);
  62.     }
  63.     return (strlen(Buf));
  64. }
  65.  
  66.